<?php
##### new wPw # LGPL Markus Schaefer , Aachen 2010
function getFeed($url){
  $time = substr(time(), 0, -3);
  $cf=md5($url).'-'.$time;
  if(file_exists($cf)&&0){return getFeedR(simplexml_load_file($cf));}
  else{
    if($fh=fopen('ftp://'.{%XXXXXX%}.'/test/cache/'.$cf,'w')){
      fwrite($fh, file_get_contents($url));
      fclose($fh);
    }else{echo time()."BBBB";echo $cf;}#debug
    return getFeedR(simplexml_load_file($url));
  }
}
function getFeedR($s){ 
    $feed = array(); 
    if(is_object($s)){ 
        settype($s,'array'); 
    } 
    foreach ($s as $key=>$value){ 
        if(is_array($value)||is_object($value)){ 
            $feed[$key] = getFeedR($value); 
        }else{ 
            $feed[$key] = $value; 
        } 
    } 
    return $feed; 
} 

function getCalendar($id){
$url='http://www.google.com/calendar/feeds/'.$id.'/public/basic?orderby=starttime&futureevents=true&sortorder=a';
return getFeed($url); 
}
function getFeedburner($id){
$url='http://feeds.feedburner.com/blogspot/'.$id.'?format=xml';
return getFeed($url); 
}
function getPicasaAlbumList($user) {
	$url = "http://picasaweb.google.com/data/feed/api/user/$user/?kind=album&access=public&alt=rss";
return getFeed($url); 
} 
function getPicasaAlbum($user, $albumid,$thumbcall) {
	$url = "http://picasaweb.google.com/data/feed/api/user/$user/albumid/$albumid?kind=photo&alt=rss&access=public&thumbsize=$thumbcall";
return getFeed($url); 
}
function getPicasaPhoto($user, $albumid, $photoid, $thumbcall) {
	$url = "http://picasaweb.google.com/data/feed/api/user/$user/albumid/$albumid/photoid/$photoid?alt=rss&thumbsize=$thumbcall";
return getFeed($url); 
} 
function get4squareVenue($vid){
$url = "https://api.foursquare.com/v1/venue?vid=$vid";
return getFeed($url); 
} 
function getDocContent($gd_doc,$gd_doc_type,$id) {
	$gd_array = array();
	if($gd_doc_type=='ssheet'){
		$gd_array[$gd_doc_type]["url"] = "https://spreadsheets.google.com/pub?key=$gd_doc&hl=en&output=html";
	}
	if($gd_doc_type=='doc'){
		$gd_array[$gd_doc_type]["url"] = "https://docs.google.com/document/pub?id=$gd_doc&amp;embedded=true";
	}

	
	$gd_array[$gd_doc_type]["start"] = '<div id="contents">';
	$gd_array[$gd_doc_type]["newstart"] = '<div id="'.$id.'">';
	$gd_array[$gd_doc_type]["end"] = '<div id="footer">';	
	$working_doc = file_get_contents($gd_array[$gd_doc_type]["url"]);
	$gd_start = strpos($working_doc,$gd_array[$gd_doc_type]["start"]);
	$gd_end = strpos($working_doc,$gd_array[$gd_doc_type]["end"]);	
	$gd_content = substr($working_doc, $gd_start, ($gd_end-$gd_start) );
#$gd_content = preg_replace('/class=\"(.*?)\"/','class="'.$id.'$1"',$gd_content);
#$gd_content = preg_replace('/<style(.*?)</style>/','class="'.$id.'$1"',$gd_content);
#    class="(.*?)"
#	$gd_content = str_replace('class="c','class="'.$id.'',$gd_content);
#	$gd_content = str_replace('.c','.'.$id,$gd_content);
#	$gd_content = str_replace($gd_array[$gd_doc_type]["start"],$gd_array[$gd_doc_type]["newstart"],$gd_content);
return $gd_content;
}
?>
